
/*
 * (C)opyright 2010, Alessandro Agosto. All rights reserved.
 * This file is part of the "pycoev" project.
 * To get more informations about the license read the LICENSE file.
 *
 * Main source file, initialize the module and defines the methods.
 */


#define PYC_MODULE_REQUIRED /*to import PyModuleDef from py3ksupport.h*/


#include "pycoev.h"
#include "pyc_pyapis.h"
#include "pyc_event.h"
#include "pyc_init.h"
#include "pyc_loop.h"


PyObject *Pyc_Error; /*pycoev.Error*/


Pyc_Methods pycoev_methods[] = {
    { "init", Pyc_Init, METH_VARARGS, Pyc_Init_Doc },
    { "deinit", (PyCFunction)Pyc_Deinit, METH_NOARGS, Pyc_Deinit_Doc },
    { NULL, NULL, 0, NULL }
};


PyDoc_STRVAR(pyc_module_doc, "Pycoev - (c) 2010, Alessandro Agosto."       CRLF
                             "Asynchronous event-interface built on the "
                             "top of the picoev library."                  CRLF
                             /*"Pycoev, as well as picoev itself, its simple"
                             " but very very powerful." */                 CRLF
                             "Does not provide a lot of features like libev"
                             ", but provides all the necessary "           CRLF
                             "to handle a file descriptor with epoll, "
                             "select and kqueue."                          CRLF
                             "To get more informations about how picoev "
                             "handles file descriptors refer to its doc."  CRLF
                             "Pycoev's license can be found in the LICENSE"
                             " file, distributed with the source code."    CRLF
                             "NOTE: Pycoev is not developed nor distributed"
                             " by Cybozy Labs, Inc."                       CRLF
                             "All rights reserved by respective owners.");


PyMODINIT_FUNC
Pyc_InitFunc(void)
{
    PyObject *pycoev;

    /*LoopType*/
    if(PyType_Ready(&LoopType)) {
        return;
    }

    pycoev = Pyc_ModInit();
    if (!pycoev) {
        return;
    }

    /*LoopType*/
    PyModule_AddObject(pycoev, "Loop", (PyObject *)&LoopType);

    /*error*/
    Pyc_Error = PyErr_NewException("pycoev.Error", NULL, NULL);
    if (!Pyc_Error) {
        Py_DECREF(pycoev);
        return;
    }

    PyModule_AddObject(pycoev, "Error", Pyc_Error);

    /*some informations*/
    PyModule_AddObject(pycoev, "__author__",
                       Py_BuildValue("s", "Alessandro Agosto"));

    PyModule_AddObject(pycoev, "__picoev__",
                       Py_BuildValue("s", "(c) 2009, Cybozu Labs, Inc."));

    PyModule_AddObject(pycoev, "__version__",
                       Py_BuildValue("(ss)", PYC_VERSION, PYC_STATUS));

    PyModule_AddObject(pycoev, "__event__",
                       Py_BuildValue("s", PYC_EVENT_BACKEND));

    /*events*/
    PyModule_AddIntConstant(pycoev, "READ", PICOEV_READ);

    PyModule_AddIntConstant(pycoev, "WRITE", PICOEV_WRITE);

    PyModule_AddIntConstant(pycoev, "READWRITE", PICOEV_READWRITE);

    PyModule_AddIntConstant(pycoev, "TIMEOUT", PICOEV_TIMEOUT);
}
